package com.example.tiantian.camera;

import java.io.File;

import com.example.tiantian.BaseActivity;
import com.example.tiantian.R;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.BitmapFactory;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class PhotoActivity extends BaseActivity implements OnClickListener, DialogInterface.OnClickListener {
    String path;

    ImageView imgMain;
    ImageView imgDel;

    @Override
    protected void init() {
        setContentView(R.layout.activity_photo);

        path = getIntent().getStringExtra("photo");

        imgMain = (ImageView) findViewById(R.id.photo_main);
        imgDel = (ImageView) findViewById(R.id.photo_del);
    }

    @Override
    protected void loadData() {
        imgMain.setImageBitmap(BitmapFactory.decodeFile(path));
    }

    @Override
    protected void event() {
        imgDel.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        new AlertDialog.Builder(this).setTitle("确定删除照片吗").setPositiveButton("取消", this).setNegativeButton("确定", this)
                .show();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        if (which == DialogInterface.BUTTON_NEGATIVE) {
            File file = new File(path);
            file.delete();
            finish();
        }
    }
}
